// jquery

/**
 * 请求对象
 * @param url 请求地址
 * @param type 请求类型
 * @param data 请求参数列表
 * @param success 请求成功回调函数
 * @param error 请求失败回调函数
 * @param async 是否异步
 */
function send(url, type, data = null, success = null, error = null, async = true) {
    $.ajax({
        url: url,
        type: type,
        data: data,
        dataType: 'json',
        contentType: 'utf8',
        success: success,
        error: error,
        async: async,
        timeout: 2000
    })
}

function printErrorInfo(error) {
    console.log(error);
}

function httpGet(url, data, success, error = printErrorInfo, async = true) {
    send(url, "GET", data, success, error, async);
}

function httpPost(url, data, success, error = printErrorInfo, async = true) {
    send(url, "POST", data, success, error, async);
}

function httpDelete(url, data, success, error = printErrorInfo, async = true) {
    send(url, "DELETE", data, success, error, async);
}

function httpPut(url, data, success, error = printErrorInfo, async = true) {
    send(url, "PUT", data, success, error, async);
}